<?php

namespace PlatBundle\Controller;

use ApiBundle\Controller\BaseController;

class CompanyController extends BaseController
{
    /*
     * 企业信息列表
     */
    public function companyListAction()
    {

        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }

        $conn = $this->get("database_connection");
        $data['company_count'] = $conn->fetchColumn("SELECT count(*) FROM company WHERE 1");

        $created_at_month = date("Y-m");

        $created_at_day = date("Y-m-d");

        $data['month_company_count'] = $conn->fetchColumn("SELECT count(*) FROM company WHERE DATE_FORMAT(created_at,'%Y-%m') = '". $created_at_month ."'");

        $data['day_company_count'] = $conn->fetchColumn("SELECT count(*) FROM company WHERE DATE_FORMAT(created_at,'%Y-%m-%d') = '". $created_at_day ."'");



        $data['medal'] = $conn->fetchAll("SELECT * FROM medal WHERE 1 ");
        $data['teac_admin'] = $conn->fetchAll("SELECT id,nickname FROM admin WHERE admin_role_id = 4 ");
        $data["category"] = $conn->fetchAll("SELECT * FROM company_category WHERE 1 ");
        $data["attribute"] = $conn->fetchAll("SELECT * FROM company_attribute WHERE 1 ");
        return $this->render("PlatBundle:Company:index.html.twig",array("data"=>$data));
    }

    /*
     * 企业基本信息
     */
    public function companyDetailMessageAction($id)
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }

        $data = $this->getApiData("ApiBundle:Platform/Company:companyDetailMessage",array("id"=>$id));
        return $this->render("PlatBundle:Company:baseMessage.html.twig",array("data"=>$data));

    }

    /*
     * 企业其他信息
     */
    public function companyOtherMessageAction($id)
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }

        $data = $this->getApiData("ApiBundle:Platform/Company:companyOtherMessage",array("id"=>$id));
        return $this->render("PlatBundle:Company:otherMessage.html.twig",array("data"=>$data));

    }
}
